capt drop _est_*

*** Count transferable vs. non-transferable



preserve
keep if $TreatmentGroup==1 
collapse transferable_cc , by(id_eez_tax $TreatmentGroup eez_name)
tab eez_name transferable_cc 
restore


********************
**   Tables ********
********************

preserve

drop if $TreatmentGroup==1  & transferable_cc==0

local Outcomelist collapsed IntoCollapse
foreach outcome of local Outcomelist {

xtset id_eez_tax iyear
reghdfe `outcome'  $Treatment  ///
$ControlsShort ///
, absorb( i.id_eez_tax i.iyear)  cluster($ClusterLevel) 
distinct id_eez_tax  if e(sample)==1
estadd scalar K1 = r(ndistinct) , replace
sum iyear if e(sample)==1
estadd  local Period "`r(min)'-`r(max)'"   , replace
sum F1.`outcome' if e(sample)==1
estadd scalar Mean = r(mean) , replace
estadd  local Controls "Short"   , replace
estadd  local FE "EEZ-specie"   , replace
distinct eez  if e(sample)==1 
estadd scalar EEZ = r(ndistinct)  , replace
eststo DID_`outcome'_2T


xtset id_eez_tax iyear
reghdfe `outcome' $Treatment    ///
$ControlsMedium ///
, absorb( i.id_eez_tax   i.iyear)  cluster($ClusterLevel) 
distinct id_eez_tax  if e(sample)==1
estadd scalar K1 = r(ndistinct) , replace
sum iyear if e(sample)==1
estadd  local Period "`r(min)'-`r(max)'"   , replace
sum F1.`outcome' if e(sample)==1
estadd scalar Mean = r(mean) , replace
estadd  local Controls "Medium"   , replace
estadd  local FE "EEZ-specie"   , replace
distinct eez  if e(sample)==1 
estadd scalar EEZ = r(ndistinct)  , replace
eststo DID_`outcome'_3T


xtset id_eez_tax iyear
reghdfe `outcome' $Treatment    ///
$ControlsLong ///
, absorb( i.id_eez_tax  i.iyear)  cluster($ClusterLevel) 
distinct id_eez_tax  if e(sample)==1
estadd scalar K1 = r(ndistinct) , replace
sum iyear if e(sample)==1
estadd  local Period "`r(min)'-`r(max)'"   , replace
sum F1.`outcome' if e(sample)==1
estadd scalar Mean = r(mean) , replace
estadd  local Controls "Long"   , replace
estadd  local FE "EEZ-specie"   , replace
distinct eez  if e(sample)==1 
estadd scalar EEZ = r(ndistinct)  , replace
eststo DID_`outcome'_4T
}

restore

************************************


estimates restore DID_IntoCollapse_2T
sum collapsed if e(sample)==1
estadd scalar MeanCol = r(mean) , replace
sum IntoCollapse if e(sample)==1
estadd scalar MeanIntoCol = r(mean) , replace
eststo DID_IntoCollapse_2_v2T
*
estimates restore DID_IntoCollapse_3T
sum collapsed if e(sample)==1
estadd scalar MeanCol = r(mean) , replace
sum IntoCollapse if e(sample)==1
estadd scalar MeanIntoCol = r(mean) , replace
eststo DID_IntoCollapse_3_v2T
*
estimates restore DID_IntoCollapse_4T
sum collapsed if e(sample)==1
estadd scalar MeanCol = r(mean) , replace
sum IntoCollapse if e(sample)==1
estadd scalar MeanIntoCol = r(mean) , replace
eststo DID_IntoCollapse_4_v2T

************************************




***************************************
**   Tables - Non-transferable ********
***************************************

preserve
drop if $TreatmentGroup==1  & transferable_cc==1

local Outcomelist collapsed IntoCollapse
foreach outcome of local Outcomelist {

xtset id_eez_tax iyear
reghdfe `outcome'  $Treatment  ///
$ControlsShort ///
, absorb( i.id_eez_tax i.iyear)  cluster($ClusterLevel) 
distinct id_eez_tax  if e(sample)==1
estadd scalar K1 = r(ndistinct) , replace
sum iyear if e(sample)==1
estadd  local Period "`r(min)'-`r(max)'"   , replace
sum F1.`outcome' if e(sample)==1
estadd scalar Mean = r(mean) , replace
estadd  local Controls "Short"   , replace
estadd  local FE "EEZ-specie"   , replace
distinct eez  if e(sample)==1 
estadd scalar EEZ = r(ndistinct)  , replace
eststo DID_`outcome'_2


xtset id_eez_tax iyear
reghdfe `outcome' $Treatment    ///
$ControlsMedium ///
, absorb( i.id_eez_tax   i.iyear)  cluster($ClusterLevel) 
distinct id_eez_tax  if e(sample)==1
estadd scalar K1 = r(ndistinct) , replace
sum iyear if e(sample)==1
estadd  local Period "`r(min)'-`r(max)'"   , replace
sum F1.`outcome' if e(sample)==1
estadd scalar Mean = r(mean) , replace
estadd  local Controls "Medium"   , replace
estadd  local FE "EEZ-specie"   , replace
distinct eez  if e(sample)==1 
estadd scalar EEZ = r(ndistinct)  , replace
eststo DID_`outcome'_3


xtset id_eez_tax iyear
reghdfe `outcome' $Treatment    ///
$ControlsLong ///
, absorb( i.id_eez_tax   i.iyear)  cluster($ClusterLevel) 
distinct id_eez_tax  if e(sample)==1
estadd scalar K1 = r(ndistinct) , replace
sum iyear if e(sample)==1
estadd  local Period "`r(min)'-`r(max)'"   , replace
sum F1.`outcome' if e(sample)==1
estadd scalar Mean = r(mean) , replace
estadd  local Controls "Long"   , replace
estadd  local FE "EEZ-specie"   , replace
distinct eez  if e(sample)==1 
estadd scalar EEZ = r(ndistinct)  , replace
eststo DID_`outcome'_4

}

restore

*********************************

estimates restore DID_IntoCollapse_2
sum collapsed if e(sample)==1
estadd scalar MeanCol = r(mean) , replace
sum IntoCollapse if e(sample)==1
estadd scalar MeanIntoCol = r(mean) , replace
eststo DID_IntoCollapse_2_v2
*
estimates restore DID_IntoCollapse_3
sum collapsed if e(sample)==1
estadd scalar MeanCol = r(mean) , replace
sum IntoCollapse if e(sample)==1
estadd scalar MeanIntoCol = r(mean) , replace
eststo DID_IntoCollapse_3_v2
*
estimates restore DID_IntoCollapse_4
sum collapsed if e(sample)==1
estadd scalar MeanCol = r(mean) , replace
sum IntoCollapse if e(sample)==1
estadd scalar MeanIntoCol = r(mean) , replace
eststo DID_IntoCollapse_4_v2

************************************


** Make a table with both outcome variables and both trans and non-trans
esttab  ///
DID_collapsed_2T ///
DID_collapsed_3T ///
DID_collapsed_4T ///
DID_collapsed_2 ///
DID_collapsed_3 ///
DID_collapsed_4 ///
using "${tables}DID_collapsed_plain_TRANS_NONTRANS_20170921.tex", ///
keep($Treatment) ///
nomtitles nogap  fragment noobs nonotes nonumbers collabels(none)  noline ///
star(* 0.10 ** 0.05 *** 0.01) se  ///
coeflabels( $Treatment "PPR"  )  ///
replace


esttab  ///
DID_IntoCollapse_2T ///
DID_IntoCollapse_3T ///
DID_IntoCollapse_4T ///
DID_IntoCollapse_2 ///
DID_IntoCollapse_3 ///
DID_IntoCollapse_4 ///
using "${tables}DID_IntoCollapse_plain_TRANS_NONTRANS_20170921.tex", ///
keep($Treatment) ///
nomtitles nogap  fragment noobs nonotes nonumbers collabels(none)  noline ///
star(* 0.10 ** 0.05 *** 0.01) se   ///
coeflabels( $Treatment "PPR"  ) ///
replace


esttab  ///
DID_IntoCollapse_2_v2T ///
DID_IntoCollapse_3_v2T ///
DID_IntoCollapse_4_v2T ///
DID_IntoCollapse_2_v2 ///
DID_IntoCollapse_3_v2 ///
DID_IntoCollapse_4_v2 ///
using "${tables}DID_info_TRANS_nonTRANS_20170921.tex", ///
drop(*) ///
nomtitles nogap  fragment  noline nonumbers ///
star(* 0.10 ** 0.05 *** 0.01) ///  
stats(Controls  N Period N_clust EEZ K1   ///
,label( "Controls (time-varying)"    "Obs" "Period" ///
 "Countries" "EEZs"  "EEZ-species" )) ///
se  coeflabels( $Treatment "PPR"  ) ///
replace



********* TRANS - Event:  Collapsed - Long controls. 2 year averages  *************
preserve

drop if $TreatmentGroup==1 & transferable_cc==0

forvalues i=60(-1)1 {
gen TimeRelPPR_m`i'=0
replace TimeRelPPR_m`i'=1 if policy_time_index==-`i'
}

forvalues i=1(1)60 {
gen TimeRelPPR_p`i'=0
replace TimeRelPPR_p`i'=1 if policy_time_index==`i'
}
***

*** Minus: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_ym`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_ym`j'=1 if TimeRelPPR_m`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

*** Positive: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_yp`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_yp`j'=1 if TimeRelPPR_p`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

xtset id_eez_tax iyear
reghdfe collapsed $Treatment  ///
$ControlsLong ///
, absorb( i.id_eez_tax i.iyear )  cluster($ClusterLevel) 
eststo results
esttab results, keep(*impl*)


xtset id_eez_tax iyear
reghdfe collapsed TimeRelPPR_ym*  TimeRelPPR_yp*  ///
$ControlsLong ///
, absorb( i.id_eez_tax i.iyear )  cluster($ClusterLevel) 
eststo results

parmest, label list(parm label estimate min* max* p) saving(results, replace)

use results, clear
gen stuff_present =  strpos(parm, "TimeRelPPR_") > 0
drop if stuff_present==0
drop dof  label
gen helpvar=_n
gen length=length(parm)
gen time_str = substr(parm,14,1)  if length==14 
replace time_str = substr(parm,14,2)  if length==15
drop if p==.
destring time_str , generate(time_num)

gen minus=0
replace minus=1 if strpos(parm, "ym")
replace time_num=time_num*-1 if minus==1 
sort time_num

label variable estimate "DiD estimate"
label variable min95 "lower 95% CI "
label variable max95 " upper 95% CI"

sum time_num
summarize helpvar
local max=r(max)
expand 2 if helpvar==`max'
gen helpvar2=_n
summarize helpvar2
local max=r(max)
replace estimate=0 if helpvar2==`max'
replace min95=0 if helpvar2==`max'
replace max95=0 if helpvar2==`max'
replace time_num=0 if helpvar2==`max'

drop if  time_num<-$TimeMin | time_num>$TimeMax

twoway ///
(rarea min95 max95 time_num , sort color(gs13)) ///
(connected  estimate time_num , sort mcolor(blue) lpattern(solid) lcolor(blue)   msymbol(o)     ) ///
, yline(0) xline(0 , lpattern(dash) ) ///
scheme(s2mono) graphregion(fcolor(white) lcolor(white)ifcolor(white) ///
ilcolor(white))  legend(on order( 1 "95% CI" 2 "DiD estimate" )) ///
xtitle(Years relative to implementation) ytitle(Effect of PPR) ///
ylab( -0.6(0.2)0.4  )  xlabel(-$TimeMin (10) $TimeMax )  scale(1.3)
graph export "${figures}\Event_Collapse_2y_ControlsLong_TRANS.${fileformat}", as(${fileformat}) /*preview(on)*/ replace
restore
**************




********* non-TRANS - Event:  Collapsed - Long controls. 2 year averages  *************
preserve

drop if $TreatmentGroup==1 & transferable_cc==1

forvalues i=60(-1)1 {
gen TimeRelPPR_m`i'=0
replace TimeRelPPR_m`i'=1 if policy_time_index==-`i'
}

forvalues i=1(1)60 {
gen TimeRelPPR_p`i'=0
replace TimeRelPPR_p`i'=1 if policy_time_index==`i'
}
***

*** Minus: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_ym`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_ym`j'=1 if TimeRelPPR_m`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****

*** Positive: 2 year averages
forvalues i=2(2)60 {
gen TimeRelPPR_yp`i'=0
}
local min = 1
local max = 2
forvalues j=2(2)60 {
forvalues i=`min'(1)`max' {
replace TimeRelPPR_yp`j'=1 if TimeRelPPR_p`i'==1
}
local j = `j' + 2
local min = `min' +2
local max = `max' +2
}
****


xtset id_eez_tax iyear
reghdfe collapsed $Treatment  ///
$ControlsLong ///
, absorb( i.id_eez_tax i.iyear )  cluster($ClusterLevel) 
eststo results
esttab results, keep(*impl*)



xtset id_eez_tax iyear
reghdfe collapsed TimeRelPPR_ym*  TimeRelPPR_yp*  ///
$ControlsLong ///
, absorb( i.id_eez_tax i.iyear )  cluster($ClusterLevel) 
eststo results

parmest, label list(parm label estimate min* max* p) saving(results, replace)

use results, clear
gen stuff_present =  strpos(parm, "TimeRelPPR_") > 0
drop if stuff_present==0
drop dof  label
gen helpvar=_n
gen length=length(parm)
gen time_str = substr(parm,14,1)  if length==14 
replace time_str = substr(parm,14,2)  if length==15
drop if p==.
destring time_str , generate(time_num)

gen minus=0
replace minus=1 if strpos(parm, "ym")
replace time_num=time_num*-1 if minus==1 
sort time_num

label variable estimate "DiD estimate"
label variable min95 "lower 95% CI "
label variable max95 " upper 95% CI"

sum time_num
summarize helpvar
local max=r(max)
expand 2 if helpvar==`max'
gen helpvar2=_n
summarize helpvar2
local max=r(max)
replace estimate=0 if helpvar2==`max'
replace min95=0 if helpvar2==`max'
replace max95=0 if helpvar2==`max'
replace time_num=0 if helpvar2==`max'

drop if  time_num<-$TimeMin | time_num>$TimeMax

twoway ///
(rarea min95 max95 time_num , sort color(gs13)) ///
(connected  estimate time_num , sort mcolor(blue) lpattern(solid) lcolor(blue)   msymbol(o)     ) ///
, yline(0) xline(0 , lpattern(dash) ) ///
scheme(s2mono) graphregion(fcolor(white) lcolor(white)ifcolor(white) ///
ilcolor(white))  legend(on order( 1 "95% CI" 2 "DiD estimate" )) ///
xtitle(Years relative to implementation) ytitle(Effect of PPR) ///
ylab( -0.6(0.2)0.4  )  xlabel(-$TimeMin (10) $TimeMax )  scale(1.3)
graph export "${figures}\Event_Collapse_2y_ControlsLong_nonTRANS.${fileformat}", as(${fileformat}) /*preview(on)*/ replace
restore
**************



capt drop _est_*
